package com.feihong.yw189.activity.kaika;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.RequiresApi;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.KeyboardUtils;
import com.bumptech.glide.Glide;
import com.cjj.Util;
import com.feihong.yw189.R;
import com.feihong.yw189.activity.base.BaseActivity;
import com.feihong.yw189.activity.dingdan.DingDanDetailsActivity;
import com.feihong.yw189.activity.kuandai.BaoZhuangAddressActivity;
import com.feihong.yw189.activity.kuandai.BaoZhuangEditActivity;
import com.feihong.yw189.activity.kuandai.ChooseSimKaActivity;
import com.feihong.yw189.activity.kuandai.HengXiangSign;
import com.feihong.yw189.activity.kuandai.ZuoJiActivity;
import com.feihong.yw189.activity.tiaoxingma.TiaoXingMaActivity;
import com.feihong.yw189.app.App;
import com.feihong.yw189.bluetooth.activity.SearchBlueActivity;
import com.feihong.yw189.bluetooth.dialog.MyUsualyDialog;
import com.feihong.yw189.dialog.PhoneNumDialog;
import com.feihong.yw189.http.HttpTools;
import com.feihong.yw189.http.ZhiWenTools;
import com.feihong.yw189.listener.PhoneNumClearListener;
import com.feihong.yw189.listener.http.RequestCallBack;
import com.feihong.yw189.message.LoginMessage;
import com.feihong.yw189.model.Kaika.AdrSelectModel;
import com.feihong.yw189.model.Kaika.FixSelectModel;
import com.feihong.yw189.model.Kaika.KaiKaSubmitPwModel;
import com.feihong.yw189.model.Kaika.KaiKaSubmitkaihuModel;
import com.feihong.yw189.model.Kaika.KaikaiJsonModel;
import com.feihong.yw189.model.Kaika.KuandaiSubmitModel;
import com.feihong.yw189.model.Kaika.TelPriceModel;
import com.feihong.yw189.model.Spec.SpecInfoModel;
import com.feihong.yw189.paidan.qiangdanservice.LocationCallBack;
import com.feihong.yw189.paidan.qiangdanservice.LocationInfo;
import com.feihong.yw189.paidan.qiangdanservice.LocationToolsOnces;
import com.feihong.yw189.utils.BigDecimalUtils;
import com.feihong.yw189.utils.UserLoginInfo;
import com.feihong.zhiwenlibrary.dialog.DJLM_PasswordDialog;
import com.feihong.zhiwenlibrary.dialog.PasswordDialogListener;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.RuntimePermissions;
import txgw.feihong.com.txgwlibrary.textview_clip.SelectableTextHelper;

import static com.feihong.yw189.activity.kaika.SelectNumActivity.AL_SELECT_TEL_NUM_KEY;
import static com.feihong.yw189.activity.kuandai.ChooseSimKaActivity.SELECT_SIM_NUM_KEY;
import static com.feihong.yw189.activity.kuandai.ZuoJiActivity.AL_SELECT_FIX_NUM_KEY;
import static com.feihong.yw189.activity.kuandai.ZuoJiActivity.SELECT_FIXPHONE_FULL_NUM_KEY;
import static com.feihong.yw189.activity.kuandai.ZuoJiActivity.SELECT_FIXPHONE_NUM_ID_KEY;
import static com.feihong.yw189.activity.kuandai.ZuoJiActivity.SELECT_FIXPHONE_NUM_KEY;

/**
 * @author wangziheng
 * @Description 开卡/办理宽带
 * @Data 2018/11/14
 */
@RuntimePermissions
public class KaiKaActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.rl_goback)
    RelativeLayout ivBack;
    @BindView(R.id.iv_lin)
    ImageView ivLin;
    @BindView(R.id.txt_pagetitle)
    TextView txtPagetitle;
    @BindView(R.id.rl_uploadpic)
    RelativeLayout rlUploadpic;
    @BindView(R.id.iv_zhengMianPic)
    ImageView ivZhengMianPic;
    @BindView(R.id.iv_beiMianPic)
    ImageView ivBeiMianPic;
    @BindView(R.id.iv_shouChiPic)
    ImageView ivShouChiPic;
    @BindView(R.id.iv_gongAnPic)
    ImageView ivGongAnPic;
    @BindView(R.id.rl_idcardinfo)
    RelativeLayout rlIDcardInfo;

    @BindView(R.id.ll_takepic)
    LinearLayout rlpic;
    @BindView(R.id.rl_xieyi)
    RelativeLayout rlxieyi;
    @BindView(R.id.ltxy)
    TextView tvltxy;
    @BindView(R.id.rl_onephone)
    RelativeLayout rlonePhone;
    @BindView(R.id.rl_twophone)
    RelativeLayout rlTwoPhone;
    @BindView(R.id.iv_taocan)
    TextView ivchooseTaoCan;
    @BindView(R.id.iv_choose_phone)
    TextView ivGetPhone;
    @BindView(R.id.rl_sign)
    RelativeLayout rlSign;
    @BindView(R.id.rl_saomiao)
    RelativeLayout rlSaoMiao;
    @BindView(R.id.ll_handpic)
    LinearLayout llHandPic;
    @BindView(R.id.iv_handsign)
    ImageView ivHandSign;

    /**
     * 套餐名称 套餐价格
     */
    @BindView(R.id.textView)
    TextView mPackageName;
    @BindView(R.id.tv_moneynumber)
    TextView mPackageDpPrice;

    @BindView(R.id.iv_headPhote)
    ImageView mIDCardImg;
    @BindView(R.id.txt_idnumber)
    TextView mIDCardNum;
    @BindView(R.id.tv_username)
    TextView mIDCardName;
    Intent mInetent;

    @BindView(R.id.kaika_submit_btn)
    Button mSubmitBtn;
    @BindView(R.id.rl_kaika_saoma)
    RelativeLayout rl_kaika_saoma;

    /**
     * 主卡
     */
    @BindView(R.id.ll_zhuka)
    LinearLayout mMainCardLayout;
    /**
     * 主副卡业务
     */
    @BindView(R.id.ll_selectICCIDParem)
    LinearLayout mSelectSimNumber;
    @BindView(R.id.ll_selectPhoneNumParem)
    LinearLayout mPhoneNumLayout;

    /**
     * 联系方式
     */
    @BindView(R.id.et_buyPhoneOne)
    EditText mContactEdit;
    /**
     * 备注信息
     */
    @BindView(R.id.et_buyPhoneTwo)
    EditText mRemarkInfo;
    /**
     * 套餐  开眼 闭眼
     */
    private Drawable mOpenEye, mCloseEye;

    @BindView(R.id.kaika_sulv_flow_layout)
    TagFlowLayout mSuLvFlowLayout;
    @BindView(R.id.kaika_sulv_layout)
    LinearLayout mSuLvLayout;
    private static final int SELECT_PHONE_NUM_REQUEST = 10;
    public static final int KAIKA_SELECT_PACKAGE_REQUEST = 11;
    public static final int KAIKA_SELECT_SIM_REQUEST = 12;
    /**
     * 图片 rep
     */
    private HashMap<String, String> mImgMap;
    /**
     * 号码 iccid信息集
     */
    private List<KaiKaSelectPhoneNumEntity> mListSelect;
    /**
     * 套餐组id  套餐id 号码id  ICCID id 证件号码 证件名称  联系方式
     */
    private String mPackageGroupID = null, mPackageID = null, mICCID_ID = null, mIDCard_Num = null, mIDCard_Name = null;
    private String orderSn;
    private String orderInfo;

    private String phoneNumText;

    /**
     * 创建的显示的手机号码textview数据
     */
    private TextView[] mTelNumTvs;
    /**
     * 选择的手机号码集合
     */
    private TreeMap<Integer, TelPriceModel> mSelectTelMap = new TreeMap<>();
    /**
     * 用以显示sim卡号的textview数组
     */
    private TextView[] mSimNumTvs;

    /**
     * 选择的sim卡号集合
     */
    private TreeMap<Integer, String> mSelectSimMap = new TreeMap<>();
    /**
     * 每一个手机号码后面跟随的清除按钮数组
     */
    private ImageView[] clearImgBtns;
    /**
     * 每一个sim卡号后面跟随的清除按钮数组
     */
    private ImageView[] simclearImgBtns;
    /**
     * 主卡信息的输入框数组  用于管理焦点
     */
    private EditText[] mMainCardEditViews;
    /**
     * 主卡信息集合
     */
    private HashMap<String, String> mMainCardInfoMap;
    /**
     * 宽带 显示的选择的地址的集合
     */
    private TextView[] mBbAdrTvs;
    /**
     * 宽带 选择地址后面跟着的清除按钮
     */
    private ImageView[] mAdrClearImgBtns;

    /**
     * 选择的地址的集合
     */
    private TreeMap<Integer, AdrSelectModel> mSelectAdrMap = new TreeMap<>();
    /**
     * 宽带  选择固话后面跟着的清除按钮
     */
    private ImageView[] mFixClearImgBtns;
    /**
     * 宽带  显示的固话集合
     */
    /**
     * 选择的固话的集合
     */
    private TreeMap<Integer, FixSelectModel> mSelectFixMap = new TreeMap<>();
    private TextView[] mBbFixTvs;
    private MyUsualyDialog mydialog;
    private String auth_kaihu;
    private String handSignUrlRep;
    private String beiMianUrl;
    private String zhengMianUrl;
    private String shouChiUrl;
    @BindView(R.id.kaika_scrollview)
    ScrollView mScrollView;
    @BindView(R.id.kaika_scrollview_childLayout)
    LinearLayout mScrollViewChildLayout;
    /**
     * 固话layout
     */
    @BindView(R.id.item_fixedTel_Layout)
    LinearLayout mFixTelLayout;
    @BindView(R.id.selectFixAllLayout)
    LinearLayout mSelectFixAllLayout;
    /**
     * 速率数据集合
     */
    private List<String> mSuLvData;
    /**
     * 需要选择的最大、最小手机号码数量
     */
    private int mMaxPhoneNum = 1, mMinPhoneNum;
    /**
     * 是否需要固定电话
     */
    private int mFixTelCount = 0;
    /**
     * 是否需要报装地址
     */
    private int mInstallAdrValue = 0;
    /**
     * 固话号码，固话ID
     */
//    private String mFixTelNum, mFixTelNumID;
    /**
     * 报装地址layout
     */
    @BindView(R.id.installAdrLayout)
    LinearLayout mInstallAdrLayout;
    /**
     * 开户类型是否为宽带   false 为开卡类型
     */
    private boolean mCreateCardTypeIsBroadBand = false;
    /**
     * 选择号码时的请求路径参数
     */
    private String mTelNumListType;
    /**
     * 提交订单时的请求路径参数
     */
    private String mSubmitOrderUrl;
    /**
     * 支付订单接口的路径参数
     */
    private String mPayPswUrl;
    /**
     * 开户接口的路径参数
     */
    private String mCreateAccountUrl;
    /**
     * 选择套餐时的请求路径参数
     */
    private String mSpecListTypeUrl;
    public static final String CREAT_CARD_TYPE_IS_BROADBAND = "CREAT_CARD_TYPE_IS_BROADBAND";
    /**
     * 选择的速率值
     */
    private String mSulvValue;
    /**
     * 判断当前页面的滑动是否是因手指滑动而滑动
     */
    private boolean isTouchMove = false;
    /**
     * 服务端返回的所需要的主卡信息的数据集
     */
    private List<SpecInfoModel.DataBean.SpecListBean.ShowParmsBean.IsInputBean> mInputMainCardInfo;
    @BindView(R.id.kk_selectPhoneNumLayout)
    LinearLayout mSelectPhoneNumLayout;
    @BindView(R.id.select_phonesim_show_layout)
    LinearLayout mSelectPhoneSimLayout;
    @BindView(R.id.selectAdrAllLayout)
    LinearLayout mselectAdrAllLayout;
    @BindView(R.id.iv_hide)
    ImageButton mHidePriceBtn;
    @BindView(R.id.kk_bottom_sumit_layout)
    LinearLayout mSubmitBtnLayout;
    /**
     * 选择号码的
     * 储存删除下标
     * 如果有连续多个的删除操作  排除操作顺序  以下标顺序为准
     * 将选择的地址 进行从小到大的插入操作
     */
    TreeMap<Integer, TelPriceModel> mTelDelMap = new TreeMap<>();
    /**
     * 选择sim卡的
     * 储存删除下标
     */
    TreeMap<Integer, String> mSimDelMap = new TreeMap<>();
    /**
     * 选择地址的
     * 储存删除下标
     */
    TreeMap<Integer, String> mAdrDelMap = new TreeMap<>();

    /**
     * 选择固话的
     * 储存删除下标
     */
    TreeMap<Integer, FixSelectModel> mFixDelMap = new TreeMap<>();

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kaika);
        KeyboardUtils.hideSoftInput(this);
        ButterKnife.bind(this);
        //注册
        mydialog = new MyUsualyDialog(KaiKaActivity.this, R.layout.wait_item);
        mydialog.setCanceledOnTouchOutside(false);
        mydialog.setCancelable(false);

        KaiKaActivityPermissionsDispatcher.requestLocaitonPerWithCheck(this);
        initView();
        initData();
    }

    private LocationToolsOnces mLocationToolsOnces;

    @NeedsPermission({Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION})
    void requestLocaitonPer() {
        mLocationToolsOnces = new LocationToolsOnces(this, mLocationCallBack);
        mLocationToolsOnces.startLocation(0);
    }

    /**
     * 定位监听
     */
    LocationCallBack mLocationCallBack = new LocationCallBack() {
        @Override
        public void successGetLocation(LocationInfo info) {
            if (activityIsDestory()) {
                return;
            }
            String mLat, mLon;
            mLat = String.valueOf(info.getLatitude());
            mLon = String.valueOf(info.getLongitude());
            UserLoginInfo.getUserLoginInfoInstance().setLocationLat(mLat);
            UserLoginInfo.getUserLoginInfoInstance().setLocationLon(mLon);
        }

        @Override
        public void error(String error) {
            if (activityIsDestory()) {
                return;
            }
        }
    };

    @Override
    public void windowStyle() {
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {


            Window window = getWindow();

            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS

                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

            window.setStatusBarColor(Color.WHITE);

        }
    }

    @Override
    public void setTheme() {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onUserLogin(LoginMessage loginMessage) {

    }

    private void initView() {
        mCreateCardTypeIsBroadBand = getIntent().getBooleanExtra(CREAT_CARD_TYPE_IS_BROADBAND, false);
        if (mCreateCardTypeIsBroadBand) {
            mTelNumListType = HttpTools.GET_KUANDAI_NUM;
            mSpecListTypeUrl = "2";
            mSubmitOrderUrl = HttpTools.BR_ORDER_SUBMIT_URL;
            txtPagetitle.setText("宽带融合");
            mPayPswUrl = HttpTools.BR_ORDER_PAY_URL;
            mCreateAccountUrl = HttpTools.BR_CREATEACCOUNT_URL;
            rlTwoPhone.setVisibility(View.VISIBLE);
        } else {
            mTelNumListType = HttpTools.GET_KK_NUM;
            mSpecListTypeUrl = "1";
            mSubmitOrderUrl = HttpTools.KK_ORDER_SUBMIT_URL;
            txtPagetitle.setText("手机开卡");
            mPayPswUrl = HttpTools.KK_ORDER_PAY_URL;
            mCreateAccountUrl = HttpTools.KK_CREATEACCOUNT_URL;
            // 隐藏联系备注信息
            rlTwoPhone.setVisibility(View.GONE);
        }
        mInputMainCardInfo = new ArrayList<>();
        mMainCardInfoMap = new HashMap<>(4);
        mImgMap = new HashMap<>();
        mListSelect = new ArrayList<>();
        mOpenEye = getResources().getDrawable(R.mipmap.hide);
        mCloseEye = getResources().getDrawable(R.mipmap.pass_gone);
        ivLin.setVisibility(View.GONE);
        rlxieyi.setVisibility(View.VISIBLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            mScrollView.setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
                if (!isTouchMove) {
                    return;
                }
                KeyboardUtils.hideSoftInput(this);
            });
        }
        mScrollView.setOnTouchListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                isTouchMove = false;
            } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
                isTouchMove = true;
            }
            return false;
        });

        String kaika_json = getActivity().getIntent().getStringExtra("kaika_json");
        if (!TextUtils.isEmpty(kaika_json)) {
            try {
                JSONObject jsonObject = new JSONObject(kaika_json);
                String spec = jsonObject.optString("spec");
                if (!TextUtils.isEmpty(spec)) {
                    KaikaiJsonModel jsonModel = JSON.parseObject(kaika_json, KaikaiJsonModel.class);
                    mPackageGroupID = jsonModel.getSpec().getSpec_g_id();
                    mPackageName.setText(jsonModel.getSpec().getSpec_name());
                    String mDPPrice = jsonModel.getSpec().getDp_price();
                    if (TextUtils.isEmpty(mDPPrice)) {
                        mDPPrice = "0";
                    }
                    mHideShowAllProce = mDPPrice;
                    String mDefaultPrice = jsonModel.getSpec().getPrice();
                    if (TextUtils.isEmpty(mDefaultPrice)) {
                        mDefaultPrice = "0";
                    }
                    mDefaultShowAllPrice = mDefaultPrice;
                    mPackageID = jsonModel.getSpec().getSpec_id();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


        mHidePriceBtn.setOnTouchListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                mPackageDpPrice.setText(String.valueOf(mDefaultShowAllPrice));
            } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (TextUtils.isEmpty(mPackageName.getText().toString())) {
                    showToast("请先选择套餐");
                } else {
                    mPackageDpPrice.setText(String.valueOf(mHideShowAllProce));
                }
            }
            return false;
        });
    }

    private SelectableTextHelper[] mSelectableTextHelpers;

    /**
     * 待优化
     * 内存抖动 --> 内存复用
     */
    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
    private void initData() {
        // 清除号码数据
        if (mTelNumTvs != null && mTelNumTvs.length > 0) {
            for (TextView textView : mTelNumTvs) {
                textView = null;
            }
            mTelNumTvs = null;
        }
        if (clearImgBtns != null && clearImgBtns.length > 0) {
            for (ImageView imageView : clearImgBtns) {
                imageView = null;
            }
            clearImgBtns = null;
        }
        Set<Map.Entry<Integer, TelPriceModel>> TelEntries = mSelectTelMap.entrySet();
        for (Map.Entry<Integer, TelPriceModel> entry : TelEntries) {
            TelPriceModel telPriceModel = entry.getValue();
            telPriceModel = null;
            entry = null;
        }
        mSelectTelMap.clear();
        // 清空sim卡数据
        if (mSimNumTvs != null && mSimNumTvs.length > 0) {
            for (TextView textView : mSimNumTvs) {
                textView = null;
            }
            mSimNumTvs = null;
        }
        if (simclearImgBtns != null && simclearImgBtns.length > 0) {
            for (ImageView imageView : simclearImgBtns) {
                imageView = null;
            }
            simclearImgBtns = null;
        }
        Set<Map.Entry<Integer, String>> SimEntries = mSelectSimMap.entrySet();
        for (Map.Entry<Integer, String> entry : SimEntries) {
            entry.setValue(null);
            entry = null;
        }
        mSelectSimMap.clear();
        // 清空主卡数据
        if (mMainCardEditViews != null && mMainCardEditViews.length > 0) {
            for (EditText editText : mMainCardEditViews) {
                editText = null;
            }
            mMainCardEditViews = null;
        }
        // 清空地址数据
        if (mBbAdrTvs != null && mBbAdrTvs.length > 0) {
            for (TextView textView : mBbAdrTvs) {
                textView = null;
            }
            mBbAdrTvs = null;
        }
        if (mAdrClearImgBtns != null && mAdrClearImgBtns.length > 0) {
            for (ImageView imageView : mAdrClearImgBtns) {
                imageView = null;
            }
            mAdrClearImgBtns = null;
        }
        if (mSelectableTextHelpers != null && mSelectableTextHelpers.length > 0) {
            for (SelectableTextHelper selectableTextHelper : mSelectableTextHelpers) {
                selectableTextHelper.destroy();
                selectableTextHelper = null;
            }
            mSelectableTextHelpers = null;
        }
        Set<Map.Entry<Integer, AdrSelectModel>> adrSelectModelEntry = mSelectAdrMap.entrySet();
        for (Map.Entry<Integer, AdrSelectModel> entry : adrSelectModelEntry) {
            AdrSelectModel adrScapModel = entry.getValue();
            adrScapModel = null;
            entry = null;
        }
        mSelectAdrMap.clear();
        // 清空固话数据
        if (mBbFixTvs != null && mBbFixTvs.length > 0) {
            for (TextView textView : mBbFixTvs) {
                textView = null;
            }
            mBbFixTvs = null;
        }
        if (mFixClearImgBtns != null && mFixClearImgBtns.length > 0) {
            for (ImageView imageView : mFixClearImgBtns) {
                imageView = null;
            }
            mFixClearImgBtns = null;
        }
        Set<Map.Entry<Integer, FixSelectModel>> FixEntries = mSelectFixMap.entrySet();
        for (Map.Entry<Integer, FixSelectModel> entry : FixEntries) {
            FixSelectModel fixSelectModel = entry.getValue();
            fixSelectModel = null;
            entry = null;
        }
        mSelectFixMap.clear();

        mPhoneNumLayout.removeAllViews();
        mSelectSimNumber.removeAllViews();
        mMainCardLayout.removeAllViews();
        mselectAdrAllLayout.removeAllViews();
        mSelectFixAllLayout.removeAllViews();
        mTelNumTvs = new TextView[mMaxPhoneNum];
        mSimNumTvs = new TextView[mMaxPhoneNum];
        mMainCardEditViews = new EditText[mInputMainCardInfo.size()];
        mBbAdrTvs = new TextView[mInstallAdrValue];
        clearImgBtns = new ImageView[mMaxPhoneNum];


        final ClearTextListener clearTextListener = new ClearTextListener();
        for (int index = 0; mMaxPhoneNum > 0 && index < mMaxPhoneNum; index++) {
            RelativeLayout relativeLayout = new RelativeLayout(this);
            mPhoneNumLayout.addView(relativeLayout);

            TextView telEditText = new TextView(this);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            telEditText.setPadding(Util.dip2px(this, 12), Util.dip2px(this, 7)
                    , Util.dip2px(this, 12), Util.dip2px(this, 8));
            telEditText.setLayoutParams(lp);
            relativeLayout.addView(telEditText);
            mTelNumTvs[index] = telEditText;
            telEditText.setFocusable(false);
            telEditText.setTextColor(getResources().getColor(R.color.black));
            telEditText.setHint(getResources().getString(R.string.kuandai_choosephonenumber1));
            telEditText.setHintTextColor(getResources().getColor(R.color.gray));
            telEditText.setTextSize(13);
            ImageView img = new ImageView(this);
            relativeLayout.addView(img);
            RelativeLayout.LayoutParams imgLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            imgLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
            imgLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
            imgLayoutParams.setMarginEnd(20);
            img.setLayoutParams(imgLayoutParams);
            img.setImageDrawable(getResources().getDrawable(R.mipmap.cha));
            img.setVisibility(View.GONE);
            clearImgBtns[index] = img;

            final int finalIndex = index;
            img.setOnClickListener(v -> clearTextListener.setTextClearListener(finalIndex));
        }

        // 选择sim卡号
        simclearImgBtns = new ImageView[mMaxPhoneNum];
        final SimClearTextListener SimclearTextListener = new SimClearTextListener();
        for (int index = 0; mMaxPhoneNum > 0 && index < mMaxPhoneNum; index++) {
            RelativeLayout relLayout = new RelativeLayout(this);

            mSelectSimNumber.addView(relLayout);

            TextView simEditText = new TextView(this);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            simEditText.setPadding(Util.dip2px(this, 12), Util.dip2px(this, 7)
                    , Util.dip2px(this, 12), Util.dip2px(this, 8));
            simEditText.setLayoutParams(lp);
            mSimNumTvs[index] = simEditText;
            simEditText.setFocusable(false);
            relLayout.addView(simEditText);
            simEditText.setBackground(null);
            simEditText.setTextColor(getResources().getColor(R.color.black));
            simEditText.setHint(getResources().getString(R.string.kuandai_choosesim_one));
            simEditText.setHintTextColor(getResources().getColor(R.color.gray));
            simEditText.setTextSize(13);

            ImageView iv = new ImageView(this);
            relLayout.addView(iv);
            RelativeLayout.LayoutParams ivLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            ivLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
            ivLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
            ivLayoutParams.setMarginEnd(20);
            iv.setLayoutParams(ivLayoutParams);
            iv.setImageDrawable(getResources().getDrawable(R.mipmap.cha));
            iv.setVisibility(View.GONE);
            simclearImgBtns[index] = iv;

            iv.setTag(index);
            iv.setOnClickListener(v -> {
                try {
                    int simfinalIndex = Integer.parseInt(v.getTag().toString());
                    SimclearTextListener.setTextClearListener(simfinalIndex);
                } catch (Exception e) {
                }
            });
        }
        // 主卡信息
        if (mInputMainCardInfo != null && mInputMainCardInfo.size() > 0) {
            mMainCardLayout.setVisibility(View.VISIBLE);
            int index = 0;
            for (SpecInfoModel.DataBean.SpecListBean.ShowParmsBean.IsInputBean mainCardInfo : mInputMainCardInfo) {
                LinearLayout linearLayout = new LinearLayout(this);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                int leftMargin = Util.dip2px(this, 14);
                layoutParams.setMargins(leftMargin, 0, leftMargin, 0);
                linearLayout.setLayoutParams(layoutParams);

                linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                TextView mainCardTitleTv = new TextView(this);
                mainCardTitleTv.setText(mainCardInfo.getName() + ":");
                mainCardTitleTv.setTextSize(13);
                mainCardTitleTv.setTextColor(getResources().getColor(R.color.black));
                linearLayout.addView(mainCardTitleTv);

                EditText mainCardInputValueEt = new EditText(this);
                LinearLayout.LayoutParams etLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                mainCardInputValueEt.setLayoutParams(etLayoutParams);
                mainCardInputValueEt.setTextSize(13);
                mainCardInputValueEt.setHint("请输入" + mainCardInfo.getName());
                mainCardInputValueEt.setHintTextColor(getResources().getColor(R.color.gray));
                mainCardInputValueEt.setTag(mainCardInfo.getValue());
                mainCardInputValueEt.setBackground(null);
                if ("number".equals(mainCardInfo.getType())) {
                    mainCardInputValueEt.setInputType(InputType.TYPE_CLASS_NUMBER);
                }
                InputFilter[] inputFilter = {new InputFilter.LengthFilter(11)};
                mainCardInputValueEt.setFilters(inputFilter);
                mainCardInputValueEt.setOnClickListener(v ->
                        KeyboardUtils.showSoftInput(v));
                mainCardInputValueEt.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {

                    }

                    @Override
                    public void afterTextChanged(Editable s) {
                        mMainCardInfoMap.put((String) mainCardInputValueEt.getTag(), s.toString());
                    }
                });
                mMainCardEditViews[index] = mainCardInputValueEt;
                linearLayout.addView(mainCardInputValueEt);
                mMainCardLayout.addView(linearLayout);
                index++;
            }
            View mainCardLineView = new View(this);
            LinearLayout.LayoutParams lineLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Util.dip2px(this, 1));
            mainCardLineView.setBackgroundColor(getResources().getColor(R.color.line));
            mainCardLineView.setLayoutParams(lineLayoutParams);
            mMainCardLayout.addView(mainCardLineView);
        } else {
            mMainCardLayout.setVisibility(View.GONE);
        }

        // 速率
        if (mSuLvData == null || mSuLvData.size() == 0) {
            mSuLvFlowLayout.setVisibility(View.GONE);
        } else {
            mSuLvFlowLayout.setVisibility(View.VISIBLE);
            LayoutInflater mSuLvInflater = LayoutInflater.from(this);
            mSuLvFlowLayout.setAdapter(new TagAdapter<String>(mSuLvData) {
                @Override
                public View getView(FlowLayout parent, int position, String sulvItem) {
                    Button button = (Button) mSuLvInflater.inflate(R.layout.sulv_item_layout, mScrollViewChildLayout, false);
                    button.setText(sulvItem);
                    return button;
                }
            });
            mSuLvFlowLayout.setOnTagClickListener((view, position, parent) -> {

                String sulvData = mSuLvData.get(position);
                if (sulvData.equals(mSulvValue)) {
                    mSulvValue = null;
                } else {
                    mSulvValue = sulvData;
                }
                return false;
            });
        }

        if (mInstallAdrValue > 0) {
            mInstallAdrLayout.setVisibility(View.VISIBLE);
            AdrClearTextListener adrClearTextListener = new AdrClearTextListener();
            mAdrClearImgBtns = new ImageView[mInstallAdrValue];
            mSelectableTextHelpers = new SelectableTextHelper[mInstallAdrValue];
            for (int adrNum = 0; adrNum < mInstallAdrValue; adrNum++) {
                RelativeLayout adrRelativeLayout = new RelativeLayout(this);
                mselectAdrAllLayout.addView(adrRelativeLayout);

                TextView adrTextView = new TextView(this);
                LinearLayout.LayoutParams adrLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                adrTextView.setPadding(Util.dip2px(this, 12), Util.dip2px(this, 7)
                        , Util.dip2px(this, 30), Util.dip2px(this, 8));
                adrTextView.setLayoutParams(adrLayoutParams);
                mBbAdrTvs[adrNum] = adrTextView;
                adrTextView.setFocusable(false);
                adrRelativeLayout.addView(adrTextView);
                adrTextView.setBackground(null);
                adrTextView.setTextColor(getResources().getColor(R.color.black));
                adrTextView.setHint(getResources().getString(R.string.kuandai_chooseAdr_hint));
                adrTextView.setHintTextColor(getResources().getColor(R.color.gray));
                adrTextView.setTextSize(13);


                ImageView adriv = new ImageView(this);
                adrRelativeLayout.addView(adriv);
                RelativeLayout.LayoutParams ivLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                ivLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
                ivLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
                ivLayoutParams.setMarginEnd(20);
                adriv.setLayoutParams(ivLayoutParams);
                adriv.setImageDrawable(getResources().getDrawable(R.mipmap.cha));
                adriv.setVisibility(View.GONE);
                mAdrClearImgBtns[adrNum] = adriv;
                adriv.setTag(adrNum);
                adriv.setOnClickListener(v -> {
                    try {
                        int adrfinalIndex = Integer.parseInt(v.getTag().toString());
                        adrClearTextListener.setTextClearListener(adrfinalIndex);
                    } catch (Exception e) {
                    }
                });
                mSelectableTextHelpers[adrNum] = new SelectableTextHelper.Builder(adrTextView)
                        .setSelectedColor(getResources().getColor(R.color.selected_blue))
                        .setCursorHandleSizeInDp(20)
                        .setCursorHandleColor(getResources().getColor(R.color.colorAccent))
                        .build();
            }
        } else {
            mInstallAdrLayout.setVisibility(View.GONE);
        }

        if (mFixTelCount > 0) {
            mFixTelLayout.setVisibility(View.VISIBLE);
            mFixClearImgBtns = new ImageView[mFixTelCount];
            mBbFixTvs = new TextView[mFixTelCount];
            FixClearTextListener fixClearTextListener = new FixClearTextListener();
            for (int fixCount = 0; fixCount < mFixTelCount; fixCount++) {
                RelativeLayout fixRelativeLayout = new RelativeLayout(this);
                mSelectFixAllLayout.addView(fixRelativeLayout);

                TextView fixTextView = new TextView(this);
                LinearLayout.LayoutParams adrLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                fixTextView.setPadding(Util.dip2px(this, 12), Util.dip2px(this, 7)
                        , Util.dip2px(this, 30), Util.dip2px(this, 8));
                fixTextView.setLayoutParams(adrLayoutParams);
                mBbFixTvs[fixCount] = fixTextView;
                fixTextView.setFocusable(false);
                fixRelativeLayout.addView(fixTextView);
                fixTextView.setBackground(null);
                fixTextView.setTextColor(getResources().getColor(R.color.black));
                fixTextView.setHint(getResources().getString(R.string.kuandai_chooseAdr_hint));
                fixTextView.setHintTextColor(getResources().getColor(R.color.gray));
                fixTextView.setTextSize(13);


                ImageView fixImg = new ImageView(this);
                fixRelativeLayout.addView(fixImg);
                RelativeLayout.LayoutParams ivLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                ivLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
                ivLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
                ivLayoutParams.setMarginEnd(20);
                fixImg.setLayoutParams(ivLayoutParams);
                fixImg.setImageDrawable(getResources().getDrawable(R.mipmap.cha));
                fixImg.setVisibility(View.GONE);
                mFixClearImgBtns[fixCount] = fixImg;
                fixImg.setTag(fixCount);
                fixImg.setOnClickListener(v -> {
                    try {
                        int fixFinalIndex = Integer.parseInt(v.getTag().toString());
                        fixClearTextListener.setTextClearListener(fixFinalIndex);
                    } catch (Exception e) {
                    }
                });
            }
        } else {
            mFixTelLayout.setVisibility(View.GONE);
        }
    }

    private static boolean isFastDoubleClick(long lastClickTime) {
        long time = System.currentTimeMillis();
        long timeD = time - lastClickTime;
        if (0 < timeD && timeD < 1000 * 1) {
            return true;
        }
        return false;
    }

    private long lastSubmitTime = 0;

    @SuppressLint("WrongConstant")
    @OnClick({R.id.rl_goback, R.id.rl_uploadpic, R.id.iv_taocan
            , R.id.rl_saomiao, R.id.btn_zuoji_number
            , R.id.iv_choose_phone, R.id.rl_sign, R.id.installAdrInputTv, R.id.installAdrSearchTv, R.id.iv_kaika_select
            , R.id.kaika_submit_btn, R.id.ltxy, R.id.rl_kaika_saoma, R.id.et_buyPhoneOne, R.id.et_buyPhoneTwo
    })
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.installAdrSearchTv:
                // 报装地址 search
                mInetent = new Intent(this, BaoZhuangAddressActivity.class);
                startActivityForResult(mInetent, 1200);
                break;
            case R.id.installAdrInputTv:
                // 报装地址 input
                mInetent = new Intent(this, BaoZhuangEditActivity.class);
                startActivityForResult(mInetent, 1201);
                break;
            case R.id.btn_zuoji_number:
                // 座机
                if (mSelectAdrMap.isEmpty() || (mSelectAdrMap.firstEntry() == null) || mSelectAdrMap.firstEntry().getKey() != 0) {
                    showToast("请先选报装地址");
                } else {
                    mInetent = new Intent(this, ZuoJiActivity.class);
                    if (TextUtils.isEmpty(mSelectAdrMap.get(0).getmInstallAdrType())) {
                        mInetent.putExtra("dire_no", mSelectAdrMap.get(0).getmInstallAdrID());
                    } else {
                        mInetent.putExtra("acc_type", mSelectAdrMap.get(0).getmInstallAdrType());
                        mInetent.putExtra("segm_id", mSelectAdrMap.get(0).getmInstallAdrID());
                    }
                    Set<Map.Entry<Integer, FixSelectModel>> fixEntries = mSelectFixMap.entrySet();
                    ArrayList<String> fixList = new ArrayList<>();
                    for (Map.Entry<Integer, FixSelectModel> entry : fixEntries) {
                        fixList.add(entry.getValue().getFixID());
                    }
                    mInetent.putStringArrayListExtra(AL_SELECT_FIX_NUM_KEY, fixList);
                    startActivityForResult(mInetent, 1202);
                }
                break;
            case R.id.et_buyPhoneOne:
                KeyboardUtils.showSoftInput(mContactEdit);
                break;
            case R.id.et_buyPhoneTwo:
                KeyboardUtils.showSoftInput(mRemarkInfo);
                break;
            case R.id.rl_goback:
                finish();//返回
                break;
            case R.id.rl_saomiao:
                //扫身份证
                mContactEdit.setFocusable(false);
                mRemarkInfo.setFocusable(false);
                for (EditText editText : mMainCardEditViews) {
                    editText.setFocusable(false);
                }
                mInetent = new Intent(this, SearchBlueActivity.class);
                mInetent.putExtra("position", "502");
                mInetent.putExtra("isUpData", true);
                mInetent.putExtra("isRead", true);
                mInetent.putExtra("isTest", "1");
                startActivityForResult(mInetent, 1550);
                break;
            case R.id.rl_uploadpic:
                //用户照片上传
                mInetent = new Intent(this, KaikaUploadPicActivity.class);
                startActivityForResult(mInetent, KaikaUploadPicActivity.KAIKA_UP_USER_IMG_REQUEST);
                break;
            case R.id.iv_taocan:
                // 选择套餐
                mInetent = new Intent(this, ChooseTaoCanActivity.class);
                mInetent.putExtra(ChooseTaoCanActivity.REQUEST_SPEC_TYPE, mSpecListTypeUrl);
                startActivityForResult(mInetent, KAIKA_SELECT_PACKAGE_REQUEST);
                break;
            case R.id.iv_choose_phone:
                if (TextUtils.isEmpty(mPackageGroupID)) {
                    showToast("请先选择套餐");
                    return;
                } else {
                    mInetent = new Intent(this, SelectNumActivity.class);
                    Set<Integer> telIndexSet = mSelectTelMap.keySet();
                    ArrayList<String> arrayList = new ArrayList<>();
                    for (Integer telIndex : telIndexSet) {
                        arrayList.add(mSelectTelMap.get(telIndex).getmTelNum());
                    }
                    mInetent.putExtra(ChooseTaoCanActivity.KAIKA_SELECT_PACAKGE_GROUPID_KEY, mPackageGroupID);
                    mInetent.putExtra(SelectNumActivity.PHONE_NUM_REQUEST_URL, mTelNumListType);
                    mInetent.putStringArrayListExtra(AL_SELECT_TEL_NUM_KEY, arrayList);
                    startActivityForResult(mInetent, SELECT_PHONE_NUM_REQUEST);
                }
                //   }
                break;
            case R.id.rl_sign:
                //手写签名
                mInetent = new Intent(this, HengXiangSign.class);
                mInetent.putExtra("position", "511");
                startActivityForResult(mInetent, 1555);
                break;
            case R.id.iv_kaika_select:
                if (TextUtils.isEmpty(mPackageName.getText().toString())) {
                    showToast("请先选择套餐");
                    return;
                } else {
                    mInetent = new Intent(KaiKaActivity.this, ChooseSimKaActivity.class);
                    Set<Integer> mSimIndexSet = mSelectSimMap.keySet();
                    ArrayList<String> arrList = new ArrayList<>();
                    for (Integer simIndexTel : mSimIndexSet) {
                        arrList.add(mSelectSimMap.get(simIndexTel));
                    }
                    mInetent.putStringArrayListExtra("simList", arrList);
                    startActivityForResult(mInetent, KAIKA_SELECT_SIM_REQUEST);
                }
                break;
            case R.id.ltxy:
                Intent tent = new Intent(KaiKaActivity.this, ServiceAgreementActivity.class);
                startActivity(tent);
                break;
            case R.id.kaika_submit_btn:
                //防止两次提交
                if (isFastDoubleClick(lastSubmitTime)) {
                    return;
                }
                KeyboardUtils.hideSoftInput(this);
                if (mRequestParams != null) {
                    mRequestParams.clear();
                } else {
                    mRequestParams = new HashMap<>();
                }

                if (TextUtils.isEmpty(mIDCard_Name)) {
                    showToast("请先扫描身份证件");
                    return;
                }
                mRequestParams.put("card_name", mIDCard_Name);
                mRequestParams.put("card_id", mIDCard_Num);

                // 套餐
                if (TextUtils.isEmpty(mPackageID)) {
                    showToast("请先选择套餐");
                    return;
                }
                mRequestParams.put("spec_id", mPackageID);
                // 报装地址
                String installAdrStrInfo;
                if (mInstallAdrValue > 0) {
                    if (mSelectAdrMap.isEmpty()) {
                        showToast("请填写报装地址");
                        return;
                    }
                    // 手输报装地址
                    try {
                        Set<Map.Entry<Integer, AdrSelectModel>> entries = mSelectAdrMap.entrySet();
                        int Adrindex = 1;
                        for (Map.Entry<Integer, AdrSelectModel> entry : entries) {
                            JSONObject jsonObject = new JSONObject();
                            if (TextUtils.isEmpty(entry.getValue().getmInstallAdrType())) {
                                jsonObject
                                        .put("stand_name", entry.getValue().getmInstallAdrName())
                                        .put("dire_no", entry.getValue().getmInstallAdrID());
                                installAdrStrInfo = jsonObject.toString();
                            } else {
                                jsonObject
                                        .put("stand_name", entry.getValue().getmInstallAdrName())
                                        .put("segm_id", entry.getValue().getmInstallAdrID())
                                        .put("acc_type", entry.getValue().getmInstallAdrType());
                                installAdrStrInfo = jsonObject.toString();
                            }
                            if (Adrindex == 1) {
                                mRequestParams.put("my_address", installAdrStrInfo);
                            } else {
                                mRequestParams.put("my_address" + Adrindex, installAdrStrInfo);
                            }
                            Adrindex++;
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                // 固话
                if (mFixTelCount > 0) {
                    if (mSelectFixMap.size() <= 0) {
                        showToast("请选择固话");
                        return;
                    }
                    try {
                        int mFixIndex = 1;
                        Set<Map.Entry<Integer, FixSelectModel>> FixEntries = mSelectFixMap.entrySet();
                        String mFixTelJson;
                        for (Map.Entry<Integer, FixSelectModel> entry : FixEntries) {
                            mFixTelJson = new JSONObject()
                                    .put("NUMBER", entry.getValue().getFixNum())
                                    .put("NUMBER_ID", entry.getValue().getFixID())
                                    .toString();
                            if (mFixIndex == 1) {
                                mRequestParams.put("my_tel", mFixTelJson);
                            } else {
                                mRequestParams.put("my_tel" + mFixIndex, mFixTelJson);
                            }
                            mFixIndex++;
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                // 速率
                if (mSuLvData != null && mSuLvData.size() != 0) {
                    if (TextUtils.isEmpty(mSulvValue)) {
                        showToast("请选择速率");
                        return;
                    }
                    mRequestParams.put("sulv", mSulvValue);
                }
                // 主卡
                if (mInputMainCardInfo != null) {
                    if (mMainCardInfoMap != null && mMainCardInfoMap.size() == mInputMainCardInfo.size()) {
                        Set<Map.Entry<String, String>> mainCardParams = mMainCardInfoMap.entrySet();
                        Iterator<Map.Entry<String, String>> mainCardIterator = mainCardParams.iterator();
                        while (mainCardIterator.hasNext()) {
                            Map.Entry<String, String> entry = mainCardIterator.next();
                            if (!TextUtils.isEmpty(entry.getValue())) {
                                mRequestParams.put(entry.getKey(), entry.getValue());
                            } else {
                                showToast("请完善主卡信息");
                                return;
                            }
                        }
                    } else {
                        showToast("请完善主卡信息");
                        return;
                    }
                }

                // 手机号码
                if (mSelectTelMap.size() < mMinPhoneNum) {
                    showToast("最少选择" + mMinPhoneNum + "个号码");
                    return;
                }
                if (mSelectSimMap.size() < mMinPhoneNum) {
                    showToast("最少选择" + mMinPhoneNum + "个ICCID");
                    return;
                }
                lastSubmitTime = System.currentTimeMillis();
                mListSelect.clear();
                if (mSelectTelMap.size() != mSelectSimMap.size()) {
                    showToast("选择的iccid数量与手机号数量不一致");
                    return;
                }
                if (mSelectSimMap.size() > 0) {
                    Set<Integer> simSet = mSelectSimMap.keySet();
                    ArrayList<String> mSimList = new ArrayList<>();
                    for (Integer simKey : simSet) {
                        mSimList.add(mSelectSimMap.get(simKey));
                    }
                    Set<Integer> telSet = mSelectTelMap.keySet();
                    ArrayList<TelPriceModel> mTelList = new ArrayList<>();
                    for (Integer telKey : telSet) {
                        mTelList.add(mSelectTelMap.get(telKey));
                    }
                    for (int phoneIndex = 0; phoneIndex < mTelList.size(); phoneIndex++) {
                        KaiKaSelectPhoneNumEntity entity = new KaiKaSelectPhoneNumEntity();
                        entity.setPhone(mTelList.get(phoneIndex).getmTelNum());
                        entity.setIccid(mSimList.get(phoneIndex));
                        mListSelect.add(entity);
                    }
                    if (mListSelect.size() > 0) {
                        String strInfo = JSON.toJSONString(mListSelect);
                        mRequestParams.put("phone", strInfo);
                    }
                }

                if (TextUtils.isEmpty(zhengMianUrl)) {
                    showToast("请上传身份证正面照");
                    return;
                }
                if (TextUtils.isEmpty(shouChiUrl)) {
                    showToast("请上传手持身份证照");
                    return;
                }
                if (TextUtils.isEmpty(beiMianUrl)) {
                    showToast("请上传身份证背面照");
                    return;
                }
                if (TextUtils.isEmpty(handSignUrlRep)) {
                    showToast("请上传签名");
                    return;
                }
                // 证件照
                String imgJson = JSON.toJSONString(mImgMap);
                mRequestParams.put("user_images", imgJson);
                // 联系人信息
                String contactTel = mContactEdit.getText().toString();
                if (TextUtils.isEmpty(contactTel)) {
                    showToast("请填写联系人电话");
                    return;
                }
                if (mCreateCardTypeIsBroadBand) {
                    mRequestParams.put("buyer_mobile", mContactEdit.getText().toString());
                } else {
                    mRequestParams.put("buyer_mobile", mContactEdit.getText().toString());
                    mRequestParams.put("order_note", mRemarkInfo.getText().toString());
                }
                mSubmitBtn.setEnabled(false);
                mydialog.show();
                mydialog.setWarningTxt(R.id.progress_layout_warning_tv, "订单提交中");
                App.getApp().getHttpTools().submitNewKaikaOrder(mSubmitOrderUrl, mRequestParams, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(String result) {
                        if (activityIsDestory()) {
                            return;
                        }
                        try {
                            if (mydialog != null && mydialog.isShowing()) {
                                mydialog.dismiss();
                            }
                            if (!TextUtils.isEmpty(result)) {
                                KuandaiSubmitModel submitModel = JSON.parseObject(result, KuandaiSubmitModel.class);
                                if (submitModel.getStatus() == 1) {
                                    //showToast("暂无后续操作");
                                    orderSn = submitModel.getData().getOrder_sn();
                                    orderInfo = submitModel.getData().getOrder_info();
                                    auth_kaihu = submitModel.getData().getAuth_kaihu();
                                    if (!TextUtils.isEmpty(orderSn)) {
                                        showKeyBoard();
                                    } else {
                                        showToast("提交失败,服务端返回的数据不正确,请重新提交！");
                                    }
                                } else {
                                    showToast("提交失败:" + submitModel.getInfo());
                                    mSubmitBtn.setEnabled(true);
                                }
                            } else {
                                mSubmitBtn.setEnabled(true);
                                showToast("服务端数据异常");
                            }
                        } catch (Exception ex) {
                            showToast("提交异常，请退出界面重新提交！");
                            mSubmitBtn.setEnabled(false);
                        }
                    }

                    @Override
                    public void onError(Throwable ex, boolean isOnCallback) {
                        if (activityIsDestory()) {
                            return;
                        }
                        mSubmitBtn.setEnabled(true);
                        if (mydialog != null && mydialog.isShowing()) {
                            mydialog.dismiss();
                        }
                        showToast(getResources().getString(R.string.connect_sever_error_toast));
                    }

                    @Override
                    public void onCancelled(Callback.CancelledException cex) {
                    }

                    @Override
                    public void onFinished() {
                    }
                });
                break;
            case R.id.rl_kaika_saoma:
                if (TextUtils.isEmpty(mPackageName.getText().toString())) {
                    showToast("请先选择套餐");
                    return;
                }
                Intent intent = new Intent(getActivity(), TiaoXingMaActivity.class);
                startActivityForResult(intent, TiaoXingMaActivity.REQ_CODE);
                break;

            default:
                break;
        }
    }

    private HashMap<String, String> mRequestParams;

    private String mDefaultShowAllPrice = "0.00";
    private String mHideShowAllProce = "0.00";

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            switch (requestCode) {
                case 1200:
                    //报装地址
                    Bundle baoZhuangBundle = data.getExtras();
                    String SelectAdrType = baoZhuangBundle.getString("Acc_type");
                    String SelectAdrID = baoZhuangBundle.getString("Segm_id");
                    String SelectAdrName = baoZhuangBundle.getString("Stand_name");
                    AdrSelectModel adrSelectModel = new AdrSelectModel();
                    adrSelectModel.setmInstallAdrID(SelectAdrID);
                    adrSelectModel.setmInstallAdrName(SelectAdrName);
                    adrSelectModel.setmInstallAdrType(SelectAdrType);
                    addAdr(adrSelectModel);
                    break;
                case 1201:
                    //手输 报装地址
                    Bundle editBZBundle = data.getExtras();
                    String InputAdrID = editBZBundle.getString("Dire_no");
                    String InputAdrName = editBZBundle.getString("inputadress");
                    AdrSelectModel adrInputSelectModel = new AdrSelectModel();
                    adrInputSelectModel.setmInstallAdrID(InputAdrID);
                    adrInputSelectModel.setmInstallAdrName(InputAdrName);
                    addAdr(adrInputSelectModel);
                    break;
                case TiaoXingMaActivity.REQ_CODE:
                    // 扫描iccid
                    String iccid = data.getStringExtra(TiaoXingMaActivity.INTENT_ICCID);
                    if (!TextUtils.isEmpty(iccid)) {
                        addICCID(iccid);
                    }
                    return;
                case SELECT_PHONE_NUM_REQUEST:
                    //选手机号
                    phoneNumText = data.getStringExtra(SelectNumActivity.KAIKA_PHONE_NUM_KEY);
                    String telPrice = data.getStringExtra(SelectNumActivity.KAIKA_NUM_PRICE);
                    String telVirtrualPrice = data.getStringExtra(SelectNumActivity.KAIKA_NUM_VIRTUAL_PRICE);
                    if (TextUtils.isEmpty(telPrice)) {
                        telPrice = "0";
                    }
                    if (TextUtils.isEmpty(telVirtrualPrice)) {
                        telVirtrualPrice = "0";
                    }
                    double mTelPrice = Double.valueOf(telPrice);
                    double mTelVirtrualPrice = Double.valueOf(telVirtrualPrice);
                    TelPriceModel telPriceModel = new TelPriceModel();
                    telPriceModel.setmTelNum(phoneNumText);
                    telPriceModel.setmTelPrice(mTelPrice);
                    telPriceModel.setmVirtualPrice(mTelVirtrualPrice);


                    if (TextUtils.isEmpty(phoneNumText)) {
                        return;
                    }
                    // 用于判断是否删除已选号码
                    TelPriceModel replaceTel;
                    int firstIndex = -1;
                    if (!mTelDelMap.isEmpty()) {
                        firstIndex = mTelDelMap.firstKey();
                        mTelDelMap.remove(firstIndex);
                    }
                    if (firstIndex >= 0) {
                        // 如果删除了号码  然后再选择新号码 那么将新选择的号码加入到被删除掉的号码集合中排在第一位的位置
                        mSelectTelMap.put(firstIndex, telPriceModel);
                        mTelNumTvs[firstIndex].setText(phoneNumText);
                        clearImgBtns[firstIndex].setVisibility(View.VISIBLE);
                    } else {
                        // 如果没有删除号码 而继续选择新的号码 ，那么 将选择的新号码 插入到已选择的号码集的最后

                        int nextKey = 0;
                        if (!mSelectTelMap.isEmpty()) {
                            if (mSelectTelMap.size() == mMaxPhoneNum) {
                                nextKey = mSelectTelMap.lastKey();
                            } else {
                                nextKey = mSelectTelMap.lastKey() + 1;
                            }
                            replaceTel = mSelectTelMap.put(nextKey, telPriceModel);
                            if (replaceTel != null) {
                                mDefaultShowAllPrice = BigDecimalUtils.sub(2, mDefaultShowAllPrice, String.valueOf(replaceTel.getmVirtualPrice()));
                                mHideShowAllProce = BigDecimalUtils.sub(2, mHideShowAllProce, String.valueOf(replaceTel.getmTelPrice()));
                            }
                        } else {
                            mSelectTelMap.put(nextKey, telPriceModel);
                        }
                        mTelNumTvs[nextKey].setText(telPriceModel.getmTelNum());
                        clearImgBtns[nextKey].setVisibility(View.VISIBLE);
                    }

                    mDefaultShowAllPrice = BigDecimalUtils.add(2, mDefaultShowAllPrice, telVirtrualPrice);
                    mHideShowAllProce = BigDecimalUtils.add(2, mHideShowAllProce, telPrice);
                    mPackageDpPrice.setText(String.valueOf(mDefaultShowAllPrice));
                    break;
                case 1555:
                    // 签名
                    llHandPic.setVisibility(View.VISIBLE);
                    handSignUrlRep = data.getStringExtra(HengXiangSign.SIGN_IMG__URL);
                    Glide.with(getActivity()).load(data.getStringExtra(HengXiangSign.SIGN_IMG__URL_REP)).into(ivHandSign);
                    if (mCreateCardTypeIsBroadBand) {
                        mImgMap.put("card_img_4_info", handSignUrlRep);
                    } else {
                        mImgMap.put("4", handSignUrlRep);
                    }
                    break;
                case 1550:
                    //身份证照片上传  //扫身份证  结果
                    Bundle bundle = data.getExtras();
                    rlIDcardInfo.setVisibility(View.VISIBLE);
                    if (bundle != null) {
                        try {
                            byte[] photo = bundle.getByteArray("photo");
                            Bitmap bitmap = BitmapFactory.decodeByteArray(photo, 0, photo.length);
                            ArrayList<String> object = bundle.getStringArrayList("phoneList");
                            PhoneNumDialog bukaDialog = new PhoneNumDialog(KaiKaActivity.this, object);
                            bukaDialog.setCancelable(true);
                            bukaDialog.show();
                            mIDCard_Num = bundle.getString("id_num");
                            mIDCard_Name = bundle.getString("name");
                            mIDCardName.setText(mIDCard_Name);
                            mIDCardNum.setText(mIDCard_Num);
                            mIDCardImg.setImageBitmap(bitmap);
                        } catch (Exception ex) {
                            showToast("读取失败,请重试");
                        }
                    }

                    break;
                case KAIKA_SELECT_PACKAGE_REQUEST:
                    // 选择套餐
                    Bundle packageBundle = data.getExtras();
                    assert packageBundle != null;
                    SpecInfoModel.DataBean.SpecListBean packageInfo = packageBundle.getParcelable(ChooseTaoCanActivity.KAIKA_SELECT_PACKAGE_KEY);
                    if (packageInfo == null) {
                        showToast("无套餐信息,请重新选择");
                        return;
                    }
                    mPackageName.setText(packageInfo.getSpec_name());
                    String mDefaultPrice = packageInfo.getPrice();
                    if (TextUtils.isEmpty(mDefaultPrice)) {
                        mDefaultPrice = "0";
                    }
                    String mDPPrice = packageInfo.getDp_price();
                    if (TextUtils.isEmpty(mDPPrice)) {
                        mDPPrice = "0";
                    }

                    mDefaultShowAllPrice = mDefaultPrice;
                    mHideShowAllProce = mDPPrice;
                    String strGroupID = packageInfo.getSpec_id();
                    mPackageID = strGroupID;
                    mPackageGroupID = packageInfo.getSpecGroupID();

                    SpecInfoModel.DataBean.SpecListBean.ShowParmsBean showParmsBean = packageInfo.getShow_parms();
                    if (showParmsBean == null) {
                        return;
                    }
                    // 报装地址  首先要清除一遍
                    mInstallAdrValue = showParmsBean.getIs_dizhi();

                    // 固话  要清除一遍
                    mFixTelCount = showParmsBean.getIs_tel();
                    SpecInfoModel.DataBean.SpecListBean.ShowParmsBean.IsPhoneBean phoneNumCountData = showParmsBean.getIs_phone();
                    mMaxPhoneNum = phoneNumCountData.getMax();
                    mMinPhoneNum = phoneNumCountData.getMin();
                    if (mMaxPhoneNum == 0) {
                        mSelectPhoneNumLayout.setVisibility(View.GONE);
                        mSelectPhoneSimLayout.setVisibility(View.GONE);
                    } else {
                        mSelectPhoneNumLayout.setVisibility(View.VISIBLE);
                        mSelectPhoneSimLayout.setVisibility(View.VISIBLE);
                        if (mMinPhoneNum > mMaxPhoneNum) {
                            mMaxPhoneNum = mMinPhoneNum;
                        }
                    }
                    // 主卡信息集

                    mMainCardInfoMap.clear();
                    mInputMainCardInfo = showParmsBean.getIs_input();
                    // 速率数据集
                    mSuLvData = showParmsBean.getIs_sulv();
                    mSulvValue = null;
                    if (mSuLvData != null && mSuLvData.size() > 0) {
                        mSuLvLayout.setVisibility(View.VISIBLE);
                    } else {
                        mSuLvLayout.setVisibility(View.GONE);
                    }

                    initData();
                    mPackageDpPrice.setText(String.valueOf(mDefaultShowAllPrice));
                    break;
                case KAIKA_SELECT_SIM_REQUEST:
                    // 选择ICCID
                    String simNum = data.getStringExtra(SELECT_SIM_NUM_KEY);
                    if (TextUtils.isEmpty(simNum)) {
                        return;
                    }
                    addICCID(simNum);
                    //mSelectSimBtn.setText(simNum);
                    break;
                case KaikaUploadPicActivity.KAIKA_UP_USER_IMG_REQUEST:
                    // 证件上传
                    rlpic.setVisibility(View.VISIBLE);
                    Glide.with(getActivity()).load(data.getStringExtra(KaikaUploadPicActivity.ZHENGMIAN_URL_REP)).into(ivZhengMianPic);
                    Glide.with(getActivity()).load(data.getStringExtra(KaikaUploadPicActivity.SHOUCHI_URL_REP)).into(ivShouChiPic);
                    Glide.with(getActivity()).load(data.getStringExtra(KaikaUploadPicActivity.BEIMIAN_URL_REP)).into(ivBeiMianPic);
                    beiMianUrl = null;
                    zhengMianUrl = null;
                    shouChiUrl = null;
                    mImgMap.clear();
                    beiMianUrl = data.getStringExtra(KaikaUploadPicActivity.BEIMIAN_URL);
                    zhengMianUrl = data.getStringExtra(KaikaUploadPicActivity.ZHENGMIAN_URL);
                    shouChiUrl = data.getStringExtra(KaikaUploadPicActivity.SHOUCHI_URL);
                    if (mCreateCardTypeIsBroadBand) {
                        mImgMap.put("handheld_img_info", shouChiUrl);
                        mImgMap.put("card_img_1_info", zhengMianUrl);
                        mImgMap.put("card_img_2_info", beiMianUrl);
                    } else {
                        mImgMap.put("1", shouChiUrl);
                        mImgMap.put("2", zhengMianUrl);
                        mImgMap.put("3", beiMianUrl);
                    }
                    break;
                case 1202:
                    //选座机号
                    Bundle zuoJiBundle = data.getExtras();
                    String FixTelNum = zuoJiBundle.getString(SELECT_FIXPHONE_NUM_KEY);
                    String FixTelNumID = zuoJiBundle.getString(SELECT_FIXPHONE_NUM_ID_KEY);
                    String fixTelNum = zuoJiBundle.getString(SELECT_FIXPHONE_FULL_NUM_KEY);

                    FixSelectModel fixSelectModel = new FixSelectModel();
                    fixSelectModel.setFixFullNum(fixTelNum);
                    fixSelectModel.setFixID(FixTelNumID);
                    fixSelectModel.setFixNum(FixTelNum);
                    int fixFirstIndex = -1;
                    if (!mFixDelMap.isEmpty()) {
                        fixFirstIndex = mFixDelMap.firstKey();
                        mFixDelMap.remove(fixFirstIndex);
                    }
                    // 如果有删除的  则根据删除的位置 进行新数据的插入操作
                    if (fixFirstIndex >= 0) {
                        mSelectFixMap.put(fixFirstIndex, fixSelectModel);
                        mBbFixTvs[fixFirstIndex].setText(fixTelNum);
                        mFixClearImgBtns[fixFirstIndex].setVisibility(View.VISIBLE);
                    } else {
                        // 如果没有删除 则进行递增操作
                        int nextKey = 0;
                        if (!mSelectFixMap.isEmpty()) {
                            if (mSelectFixMap.size() == mFixTelCount) {
                                // 如果集合已满  替换最后一个
                                nextKey = mSelectFixMap.lastKey();
                            } else {
                                nextKey = mSelectFixMap.lastKey() + 1;
                            }
                        }
                        mSelectFixMap.put(nextKey, fixSelectModel);
                        mBbFixTvs[nextKey].setText(fixTelNum);
                        mFixClearImgBtns[nextKey].setVisibility(View.VISIBLE);
                    }
                    break;
                default:
                    break;
            }
        }
    }

    /**
     * 插入 地址
     *
     * @param adrSelectModel
     */
    private void addAdr(AdrSelectModel adrSelectModel) {
        int adrFirstIndex = -1;
        if (!mAdrDelMap.isEmpty()) {
            adrFirstIndex = mAdrDelMap.firstKey();
            mAdrDelMap.remove(adrFirstIndex);
        }
        if (adrFirstIndex >= 0) {
            // 如果有删除的数据 则根据删除的位置  进行新数据的插入操作
            mSelectAdrMap.put(adrFirstIndex, adrSelectModel);
            mBbAdrTvs[adrFirstIndex].setText(adrSelectModel.getmInstallAdrName());
            mAdrClearImgBtns[adrFirstIndex].setVisibility(View.VISIBLE);
        } else {
            // 如果没有删除地址  则将新选择的地址直接插入到集合中
            int nextKey = 0;
            if (!mSelectAdrMap.isEmpty()) {
                if (mSelectAdrMap.size() == mInstallAdrValue) {
                    // 如果集合已满 则替换最后一个
                    nextKey = mSelectAdrMap.lastKey();
                } else {
                    nextKey = mSelectAdrMap.lastKey() + 1;
                }
            }
            mSelectAdrMap.put(nextKey, adrSelectModel);
            mBbAdrTvs[nextKey].setText(adrSelectModel.getmInstallAdrName());
            mAdrClearImgBtns[nextKey].setVisibility(View.VISIBLE);
        }
    }

    /**
     * 插入  iccid
     *
     * @param simNum
     */
    private void addICCID(String simNum) {
        int firstSimIndex = -1;
        if (!mSimDelMap.isEmpty()) {
            firstSimIndex = mSimDelMap.firstKey();
            mSimDelMap.remove(firstSimIndex);
            mSelectSimMap.put(firstSimIndex, simNum);
        }
        if (firstSimIndex >= 0) {
            mSimNumTvs[firstSimIndex].setText(simNum);
            simclearImgBtns[firstSimIndex].setVisibility(View.VISIBLE);
        } else {
            if (!mSelectSimMap.isEmpty()) {
                int nextKey;
                if (mSelectSimMap.size() == mMaxPhoneNum) {
                    nextKey = mSelectSimMap.lastKey();
                } else {
                    nextKey = mSelectSimMap.lastKey() + 1;
                }
                mSelectSimMap.put(nextKey, simNum);
            } else {
                mSelectSimMap.put(0, simNum);
            }
            int index = 0;
            Set<Integer> keySet = mSelectSimMap.keySet();
            Iterator<Integer> iterator = keySet.iterator();
            while (iterator.hasNext()) {
                index = iterator.next();
                mSimNumTvs[index].setText(mSelectSimMap.get(index));
                simclearImgBtns[index].setVisibility(View.VISIBLE);
            }
        }
    }

    DJLM_PasswordDialog pwdDialog;

    /**
     * 是否执行到了支付密码这里
     */
    private boolean isPayPsw = false;

    /**
     * 支付密码  请求
     */
    private void subOrderNet(final String orderSn, final String password, final String orderInfo, String touch_pwd, String randomNum) {
        isPayPsw = true;
        App.getApp().getHttpTools().getKaiKaPassWorld(orderSn, password, touch_pwd, randomNum, mPayPswUrl, new RequestCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                if (activityIsDestory()) {
                    return;
                }
                try {
                    KaiKaSubmitPwModel submitPwModel = JSON.parseObject(result, KaiKaSubmitPwModel.class);
                    if (submitPwModel.getStatus() == 1) {
                        if (!TextUtils.isEmpty(auth_kaihu) && auth_kaihu.equals("0")) {
                            pwdDialog.dismiss();
                            mInetent = new Intent();
                            mInetent.setClass(KaiKaActivity.this, DingDanDetailsActivity.class);
                            mInetent.putExtra("order_sn", orderSn);
                            mInetent.putExtra("orderInfo", orderInfo);
                            startActivity(mInetent);
                            finish();
                        } else if (!TextUtils.isEmpty(auth_kaihu) && auth_kaihu.equals("1")) {
                            App.getApp().getHttpTools().getKaiKaKaiHu(orderSn, mCreateAccountUrl, new RequestCallBack<String>() {
                                @Override
                                public void onSuccess(String result) {

                                }

                                @Override
                                public void onError(Throwable ex, boolean isOnCallback) {
                                }

                                @Override
                                public void onCancelled(Callback.CancelledException cex) {
                                }

                                @Override
                                public void onFinished() {
                                    if (activityIsDestory()) {
                                        return;
                                    }
                                    KaiKaSubmitkaihuModel model = JSON.parseObject(result, KaiKaSubmitkaihuModel.class);
                                    pwdDialog.dismiss();
                                    mInetent = new Intent();
                                    mInetent.setClass(KaiKaActivity.this, DingDanDetailsActivity.class);
                                    mInetent.putExtra("order_sn", orderSn);
                                    mInetent.putExtra("orderInfo", orderInfo);
                                    String re_trandis = String.valueOf(model.getData().getReq_transid());
                                    mInetent.putExtra("req_transid", String.valueOf(model.getData().getReq_transid() + ""));
                                    startActivity(mInetent);
                                    finish();
                                }
                            });
                        } else {
                            pwdDialog.dismiss();
                            mInetent = new Intent(KaiKaActivity.this, DingDanDetailsActivity.class);
                            mInetent.putExtra("order_sn", orderSn);
                            mInetent.putExtra("orderInfo", orderInfo);
                            startActivity(mInetent);
                            finish();
                        }
                    } else {
                        pwdDialog.dismiss();
                        showToast(submitPwModel.getInfo());
                        mInetent = new Intent(KaiKaActivity.this, DingDanDetailsActivity.class);
                        mInetent.putExtra("order_sn", orderSn);
                        mInetent.putExtra("orderInfo", orderInfo);
                        startActivity(mInetent);
                        finish();
                    }
                } catch (Exception ex) {
                    pwdDialog.dismiss();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                if (activityIsDestory()) {
                    return;
                }
                showToast(getResources().getString(R.string.connect_sever_error_toast));
                pwdDialog.dismiss();
            }

            @Override
            public void onCancelled(Callback.CancelledException cex) {
            }

            @Override
            public void onFinished() {
            }
        });
    }

    private void showKeyBoard() {
        if (pwdDialog != null && pwdDialog.isAdded()) {
            pwdDialog.dismiss();
        }
        pwdDialog = new DJLM_PasswordDialog(KaiKaActivity.this);
        pwdDialog.setCallBack(new PasswordDialogListener() {
            @Override
            public void onDoneInput(DJLM_PasswordDialog dialog, final String pwd) {
                pwdDialog.showLoadingView();
                new Handler().postDelayed(() -> subOrderNet(orderSn, pwd, orderInfo, "", ""), 1000);
            }

            @Override
            public void successFinger(DJLM_PasswordDialog dialog) {
                pwdDialog.showLoadingView();
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        String random = ZhiWenTools.getRandNum();
                        String pwd = ZhiWenTools.getZhiWenPwd(random);
                        String touch_pwd = ZhiWenTools.getZhiWebKey();
                        subOrderNet(orderSn, pwd, orderInfo, touch_pwd, random);
                    }
                }, 1000);
            }

            @Override
            public void onBtnClick(int type) {
                if (type == 3 && !isPayPsw) {
                    pwdDialog.dismiss();
                    mInetent = new Intent();
                    mInetent.setClass(KaiKaActivity.this, DingDanDetailsActivity.class);
                    mInetent.putExtra("order_sn", orderSn);
                    mInetent.putExtra("orderInfo", orderInfo);
                    startActivity(mInetent);
                    finish();
                }
            }
        });
        if (ZhiWenTools.isSupportZhiWenPay(pwdDialog)) {
            pwdDialog.setEnableFinger(true);
        } else {
            pwdDialog.setEnableFinger(false);
        }
        pwdDialog.show(getSupportFragmentManager(), "支付键盘");
        //pwdDialog.setEnableFinger(false);//关闭指纹支付功能，只用密码支付

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    class ClearTextListener implements PhoneNumClearListener {

        @Override
        public void setTextClearListener(int i) {
            mTelNumTvs[i].setText(null);
            mTelNumTvs[i].setHint(getResources().getString(R.string.kuandai_choosephonenumber1));
            clearImgBtns[i].setVisibility(View.GONE);
            TelPriceModel telPriceModel = mSelectTelMap.remove(i);
            mDefaultShowAllPrice = BigDecimalUtils.sub(2, mDefaultShowAllPrice, String.valueOf(telPriceModel.getmVirtualPrice()));
            mHideShowAllProce = BigDecimalUtils.sub(2, mHideShowAllProce, String.valueOf(telPriceModel.getmTelPrice()));
            mTelDelMap.put(i, telPriceModel);
            mPackageDpPrice.setText(String.valueOf(mDefaultShowAllPrice));
        }
    }

    class SimClearTextListener implements PhoneNumClearListener {
        @Override
        public void setTextClearListener(int i) {
            String strSim = mSimNumTvs[i].getText().toString();
            mSimDelMap.put(i, strSim);
            mSimNumTvs[i].setText(null);
            mSimNumTvs[i].setHint(getResources().getString(R.string.kuandai_choosesim_one));
            simclearImgBtns[i].setVisibility(View.GONE);
            mSelectSimMap.remove(i);
        }
    }

    class AdrClearTextListener implements PhoneNumClearListener {
        @Override
        public void setTextClearListener(int i) {
            String oldAdr = mBbAdrTvs[i].getText().toString();
            mAdrDelMap.put(i, oldAdr);
            mAdrClearImgBtns[i].setVisibility(View.GONE);
            mBbAdrTvs[i].setText(null);
            mBbAdrTvs[i].setHint(getString(R.string.kuandai_chooseAdr_hint));
            mSelectAdrMap.remove(i);
            if (i == 0) {
                // 如果是删除的第一个地址  则需要重新选择固话
                mSelectFixMap.clear();
                mFixDelMap.clear();
                if (mBbFixTvs != null && mBbFixTvs.length > 0) {
                    for (TextView textView : mBbFixTvs) {
                        textView.setText(null);
                        textView.setHint(getString(R.string.kuandai_gudingnumber_txt));
                    }
                }
                if (mFixClearImgBtns != null && mFixClearImgBtns.length > 0) {
                    for (ImageView imageView : mFixClearImgBtns) {
                        imageView.setVisibility(View.GONE);
                    }
                }
            }
        }
    }

    class FixClearTextListener implements PhoneNumClearListener {
        @Override
        public void setTextClearListener(int i) {
            mFixDelMap.put(i, mSelectFixMap.remove(i));
            mFixClearImgBtns[i].setVisibility(View.GONE);
            mBbFixTvs[i].setText(null);
            mBbFixTvs[i].setHint(getString(R.string.kuandai_gudingnumber_txt));
        }
    }

    class KaiKaSelectPhoneNumEntity {
        private String phone, iccid;

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

        public String getIccid() {
            return iccid;
        }

        public void setIccid(String iccid) {
            this.iccid = iccid;
        }
    }
}





